package com.site.wisdom_construction.controller.qualityModule;

import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.qualityModule.QualityInspectionRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/1/13
 * @Description
 */
@Api(tags = "质量巡检记录接口")
@RestController
@RequestMapping("QualityInspectionRecord")
@CrossOrigin
public class QualityInspectionRecordController {
    @Autowired
    private QualityInspectionRecordService qualityInspectionRecordService;

    @ApiOperation(value = "增加巡检记录", notes = "测试数据:")
    @PostMapping("/insertQualityInspectionRecord")
    public JsonResult insertQualityInspectionRecord(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = qualityInspectionRecordService.insertQualityInspectionRecord(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功录入巡检记录!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("录入巡检记录失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "删除巡检记录信息", notes = "测试数据:")
    @PostMapping("/deleteQualityInspectionRecord")
    public JsonResult deleteQualityInspectionRecord(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        List<Integer> list = (List<Integer>) map.get("list");
        int l = 0;
        Map mapR = new HashMap();
        for (int i = 0;i<list.size();i++){
            mapR.put("id",list.get(i));
            int a = qualityInspectionRecordService.deleteQualityInspectionRecord(mapR);
            l+=a;
        }
        if (l>=1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除巡检记录!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除巡检记录失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "修改巡检记录", notes = "测试数据:")
    @PostMapping("/updateQualityInspectionRecord")
    public JsonResult updateQualityInspectionRecord(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = qualityInspectionRecordService.updateQualityInspectionRecord(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功修改巡检记录!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("修改巡检记录失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页模糊查询巡检记录", notes = "测试数据:")
    @PostMapping("/findQualityInspectionRecordByPage")
    public Page findQualityInspectionRecordByPage(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(qualityInspectionRecordService.Total(map));
        page.setItems(qualityInspectionRecordService.findQualityInspectionRecordByPage(map));
        return page;
    }
}
